#!/bin/bash
Download="http://rlya.site/lnmp/source"
Downurl="https://gitee.com/RuoliCloud/lnmp-script/raw/master"
system=`rpm -q centos-release|cut -d- -f3`
echo -e "----------   LNMP一键脚本   ----------"
read -p "输入y继续安装(其余按键退出)" first
if [ $first != "y" ]; then
    clear
    echo -e "已退出脚本"
    exit
fi
read -p "输入首个网站用户名:" username
read -p "输入Mysql密码:" passwd
yum -y install wget
#更换YUM源
wget https://gitee.com/RuoliCloud/YUMsh/raw/master/yumcd.sh -O yumcd.sh
sh yumcd.sh -A
#准备NGINX YUM源
wget $Downurl/nginx.repo -O /etc/yum.repos.d/nginx.repo
#安装PCRE
yum -y install make
cd /usr/local/src/
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
tar zxvf pcre-8.35.tar.gz
cd pcre-8.35
./configure
make
make install
#NGINX依赖库安装
yum -y install zlib zlib-devel gcc-c++ libtool  openssl openssl-devel
#安装NGINX
cd /usr/local/src/
wget http://nginx.org/download/nginx-1.22.0.tar.gz
tar zxvf nginx-1.22.0.tar.gz
cd nginx-1.22.0
./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
make
make install
clear
/usr/sbin/groupadd www 
/usr/sbin/useradd -g www www
wget $Downurl/nginx.conf -O /usr/local/webserver/nginx/conf/nginx.conf
/usr/local/webserver/nginx/sbin/nginx
#安装Mysql
case $system in
    6)
    wget https://repo.mysql.com/mysql80-community-release-el6-7.noarch.rpm
    rpm -ivh mysql80-community-release-el6-7.noarch.rpm
    yum update
    yum install mysql-server
    ;;
    7)
    wget https://repo.mysql.com/mysql80-community-release-el7-7.noarch.rpm
    rpm -ivh mysql80-community-release-el7-7.noarch.rpm
    yum update
    yum install mysql-server
    ;;
    8)
    wget https://repo.mysql.com/mysql80-community-release-el8-4.noarch.rpm
    rpm -ivh mysql80-community-release-el8-4.noarch.rpm
    yum update
    yum install mysql-server
    ;;
esac
chown -R mysql:mysql /var/lib/mysql/
mysqld --initialize
systemctl start mysqld
mysqladmin -u root password "${passwd}";
#PHP7.2安装
yum install epel-release -y
pm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y remove php*
yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel
systemctl enable php-fpm.service systemctl start php-fpm.service
clear
echo -e "安装完成 请手动查看"
